import { v4 as uuidv4 } from "uuid";

export enum Operator {
  /**
   * 相等
   */
  EQ = 1,
  /**
   * 不相等
   */
  NEQ = 2,
  /**
   * 在某个集合中
   */
  IN = 3,
  /**
   * 不在某个集合中
   */
  NOT_IN = 4,
  /**
   * 小于, <
   */
  LT = 5,
  /**
   * 大于，>
   */
  GT = 6,
  /**
   * 不大于， <=
   */
  NGT = 7,
  /**
   * 不小于, >=
   */
  NLT = 8,
  /**
   * 在某个范围内, 闭区间
   */
  RIN = 9,

  /**
   * 多个区间的组合
   * 仅限内部使用
   */
  SEGMENTS_INNER = 10,

  /**
   * 左开右闭区间
   */
  LO_IN_INNER = 11,
  /**
   * 左闭右开区间
   */
  RO_IN_INNER = 12,
  /**
   * 开区间
   */
  O_IN_INNER = 13,

  /**
   * 全集
   */
  FULL = 14,

  /**
   * 空集
   */
  EMPTY = 15,
}

export enum BoolOperation {
  AND = 1,
  OR = 2,
  // NOT = 3, // 暂时先不考虑
  // XOR = 4, // 暂时不考虑
}

export type ValueType = number | string | number[] | string[] | BoolItem[];
export interface BoolItem {
  uuid?: string;
  key: string;
  operator: Operator;
  value: ValueType;
}

export interface BoolExpression {
  operator: BoolOperation;
  args: Expression[];
}

export type Expression = BoolExpression | BoolItem;

export const EMPTY = Object.freeze({
  uuid: uuidv4(),
  key: 'not_matter',
  operator: Operator.EMPTY,
  value: 0,
});

export const FULL = Object.freeze({
  uuid: uuidv4(),
  key: 'not_matter',
  operator: Operator.FULL,
  value: 0,
});
